package com.zsw.controller;

import com.zsw.entity.Order;
import com.zsw.exception.ResponseBaseDTO;
import com.zsw.exception.ResponseDTO;
import com.zsw.service.OrderService;
import com.zsw.gen.ResultUtil;
import com.zsw.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.aspectj.weaver.ast.Or;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * @author zhangsw
 */
@RestController
@Api("订单服务")
public class OrderController {

    @Resource
    OrderService orderService;

    @ApiOperation("创建订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "用户Id"),
            @ApiImplicitParam(name = "commodityCode",value = "商品代号"),
            @ApiImplicitParam(name = "orderCount",value = "商品数量"),
    })
    @PostMapping(value = "/order/purchase",produces = "application/json")
    public ResultVO purchase(int userId, int commodityCode, int orderCount) throws Exception {
        Order order=orderService.createOrder(userId, commodityCode, orderCount);
        if (null==order){
            return ResultUtil.fail("fail to generate order!",500);
        }
        return ResultUtil.success("generate order success!",order);
    }
}
